import { createRouter, createWebHashHistory } from 'vue-router'
import ShopIndex from '../components/user/ShopIndex.vue'
import ShopLogin from '../components/user/ShopLogin.vue'
import UserMan from '../components/power/UserMan.vue'
import RotMan from '../components/power/RotMan.vue'
import PowMan from '../components/power/PowMan.vue'
import HomePage from '../components/user/HomePage.vue'
import Cate from '../components/goods/Cate.vue'
import Goods from '../components/goods/Goods.vue'
import Params from '../components/goods/Params.vue'
import Add from '../components/goods/Add.vue'
import Orders from '../components/order/Order.vue'
import Reports from '../components/reports/Reports.vue'

const routes = [
  {
    path: '/',       //默认显示初始界面
    component: ShopLogin
  },
  {
    path: '/login',
    component: ShopLogin
  },
  {
    path: '/index',
    component: ShopIndex,
    redirect: 'index/homepage',
    children: [
      { path: 'homepage', component: HomePage,},
      { path: 'users', component: UserMan,},
      { path: 'roles', component: RotMan},
      { path: 'rights', component: PowMan},
      { path: 'categories', component: Cate,},
      { path: 'goods', component: Goods,},
      { path: '/goods/add', component: Add,},
      { path: 'params', component: Params,},
      { path: 'orders', component: Orders,},
      { path: 'reports', component: Reports,},
    ]
  },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

// router.beforeEach((to, form, next) => {
//   let token = window.sessionStorage.getItem("token")
//   if (to.path=="/login") {
//     next
//   } else {
//     if (!token) {
//       return next('/login')
//     } else {
//       next()
//     }
//   }
// })

export default router
